<%--
  Created by IntelliJ IDEA.
  User: zl
  Date: 2021/10/29
  Time: 10:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/layui/layui/layui.js"></script>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui/layui/css/layui.css"/>
</head>
<body>
<div class=" ">
    <div class=" ">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
<%--                            <label class="l V                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   GVayui-form-label">类型ID</label>--%>
                            <div clat4  6ss="layui-input-inline">
                                <input type="text" name="booktype" autocomplete="off" class="layui-input" placeholder="请输入书籍类型">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="searchBtn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <%--<script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">新增</button>
            </div>
        </script>--%>

         <table class="layui-hide" id="teaTable" lay-filter="teaTable"></table>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">批量删除书籍类型</button>
                <button class="layui-btn layui-btn-sm" lay-event="add">添加书籍类型</button>
            </div>
        </script>

        <script type="text/html" id="currentTableBar">
            {{# if(d.he>0){ }}
            <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="edit">修改</a>
            <a class="layui-btn layui-btn-xs layui-btn-disabled data-count-delete">删除</a>
            {{# }else{ }}
            <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="edit">修改</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete"  lay-event="delete">删除</a>

            {{# } }}
        </script>
    </div>
</div>
<%-- 新增表单--%>
<form class="layui-form" action="" lay-filter="biaodan"  style="display: none" id="addform">
    <input id="typeid" name="typeid" hidden>
    <div class="layui-form-item">
        <label class="layui-form-label">书籍类型</label>
        <div class="layui-input-inline">
            <input type="text" name="booktype" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
<!-- 资 源 引 入 -->
<%--<script src="component/layui/layui.js"></script>--%>
<%--<script src="component/pear/pear.js"></script>--%>
<script>
    layui.use(["table","form","jquery"],function (){
        var table=layui.table;
        var form=layui.form;
        var $=layui.jquery;
        //执行一个 table 实例
        table.render({
            elem:'#teaTable',
            url:'/bookType/selectTeacher',
            toolbar:'#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'typeid', title: '类型ID',  sort: true, fixed: 'left' }
            ,{field: 'booktype', title: '书籍类型' }
                ,{field: 'zj', title: '书籍种类数量'}
                ,{field: 'he', title: '该类型库存总和'}

            ,{title: '操作', width: 150, toolbar: '#currentTableBar'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line',
            id:"teaTable"
        });
        // 监听搜索操作
        form.on('submit(searchBtn)', function (data) {
            //执行搜索重载
            table.reload('teaTable', {
                page: {
                    curr: 1
                }
                , where: data.field
            });
            return false;
        });

        //新增
        form.on('submit(formDemo)', function (data) {
            //执行搜索重载
            $.ajax({
                url:"/bookType/insertTeacher",
                data:data.field,
                type:"post",
                dataType:"json",
                success:function (reDate){
                    console.log(reDate);
                    if (reDate.code=1){
                        //执行重载
                        table.reload('teaTable', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        })
                        layer.closeAll();
                    }else{
                        alert(reDate.msg);
                    }
                }
            })
            return false;
        });

        //工具栏事件  新增或修改弹出框
        table.on('toolbar(teaTable)', function(obj){
            switch(obj.event){
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
                case 'add':
                    $('#addform')[0].reset(); /*清空表单*/
                    layer.open({
                        content:$('#addform')
                        ,type:1,
                        title:['书籍信息','font-size:25px;'],

                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(teaTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'delete'){
                layer.confirm('确认删除吗', function(index){
                    $.ajax({
                        url:"/bookType/deleteTeacher"
                        ,type:"post"
                        ,data:{typeid:data.typeid}
                        ,success:function (a) {
                            if (a.code==1){
                                table.reload("teaTable");
                            }else{
                                layer.msg('失败', {icon: 5});
                            }
                        }
                    })
                    layer.close(index);
                });

            } else if(obj.event === 'edit'){
console.log(data);
                form.val("biaodan", data);
                layer.open({
                    content:$('#addform')
                    ,type:1
                    ,skin: 'layui-layer-molv',
                })
            }
        });
    });
</script>
</body>
</html>
